package com.kdtech.analyse.NewsPaper;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.analyse.AnalyseNews;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.RegexUtils;
import com.kdtech.utils.StringUtils;

/**
 *http://epaper.nbd.com.cn/ 每日经济新闻
 * 
 * @author KK
 * 
 */
public class NbdNewsPaperAnalyse implements AnalyseNews {

	
	public boolean isDetailPage(String url) {
		String[] regex = { "http://www.nbd.com.cn/articles/[0-9]{4}-[0-9]{2}-[0-9]{2}/[0-9]*.html", };
		return RegexUtils.matchAny(url, regex);
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {

		String html = urlMeta.getHtml();
		String url = urlMeta.getUrl();

		String title = null;
		String content = null;
		String author =null;
		Long date = null;
		Document doc = Jsoup.parse(html);

		title = doc.select("h1").text();
		date = DateUtils.matchDate(doc.select("span.time").text());
        author = doc.select("span.source").text();
		content = HtmlCleaner.getContentHtml(url, doc
				.select("div.g-article"));

		NewsMeta newspaper = new NewsMeta();
		newspaper.setUrl(url);
		newspaper.setTitle(StringUtils.trimSpace(title));
		newspaper.setContent(StringUtils.trimSpace(content));
		newspaper.setAuthor(author);
		newspaper.setDate(date);
		return newspaper;

	}

	
	public boolean isTaskPage(String url) {
		String[] regex = {

		};
		return RegexUtils.matchAny(url, regex);
	}

	
}
